<?php
/**
  * Musashi - A project manager for music groups and bands
  * Copyright (C) 2010 Daniel Torres
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  */

// Make sure we have access to this page
defined('_JEXEC') or die ('Restricted access. Sorry');

// Validate this page. This prevents unknown users from sending forms to our controller objects
$session =& JFactory::getSession();
$session->set('validFormCheck',true);
$session->set('musashiRedirect',JRoute::_('index.php?option=com_musashi&controller=user&view=user'));

// If we have a message, get it here, and reset.
$msg = $session->get('actionResult','');
$session->set('actionResult','');

// Add the stylesheet for this page
JHTML::_('stylesheet','base.css','components/com_musashi/views/common/');
JHTML::_('stylesheet','default.css','components/com_musashi/views/user/tmpl/');

?>
<script language="javascript" type="text/javascript">
<!--
    // Form validation
    function validateForm()
    {
        var form = document.registerForm;
        
        // Make sure the following fields are not empty
        if(form.cell.value == "" && form.phone.value == "")
        {
            alert("Please provide at least one phone number");
            return false;
        }
        
        // Must have an address
        if( form.email.value == "" )
        {
            alert("Please provide an email, so we can contact you with alerts and other important information");
            return false;
        }
        else
        {
            apos   = form.email.value.indexOf("@");
            dotpos = form.email.value.lastIndexOf(".");
            if ((apos < 1) || (dotpos-apos < 2)) {
                alert("Please correct your email address")
                return false;
            }
        }
        
        // Make sure we have an address
        if( form.address.value == "")
        {
            alert("Please, let us know where you live");
            return false;
        }
    
        // Submit
        return true;
    }
//-->
</script>
        <!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
        <!--[if lte IE 7]><script src="js/IE8.js" type="text/javascript"></script><![endif]-->
        <!--[if lt IE 7]><link rel="stylesheet" type="text/css" media="all" href="css/ie6.css"/><![endif]-->        

        <musashiContent id="content" class="body">
            
            <!-- Page header and title -->
            <header id="title" class="body">
                <div class="name">
                    <h1>Your Information</h1>
                </div>
                <div class="description">
                    <p>In this section, you can update personal information such as phone
                    numbers, your date of birth, email, address, etc. Make sure all information
                    is up to date, so other members can get in touch with you</p>
                </div>
            </header>
            
            <!-- Things that need to be responded to -->
            <section id="notice" class="body">
                <div class="notice-title">
                    <h1><?php echo $this->name; ?></h1><h2>Update your information as required</h2>
                    <?php
                        if ($msg != "")
                        {?>
                            <div class="action-result"><?php echo $msg; ?></div>        
                        <?php
                        }
                    ?>                    
                </div>
                <form id="user-data" name="registerForm" method="post" onsubmit="return validateForm()" action="<?php echo JRoute::_('index.php?option=com_musashi&controller=user&view=user&task=update');?>">
                    <fieldset>
                        <ol>
                            <li>
                                <label for="phone">Home Phone</label>
                                <input id="phone" name="phone" type="tel" placeholder="xxx-xxx-xxxx" value="<?php echo $this->data->phone; ?>">
                            </li>
                            <li>
                                <label for="phone">Cell Phone</label>
                                <input id="cell" name="cell" type="tel" placeholder="xxx-xxx-xxxx" value="<?php echo $this->data->cell; ?>">
                            </li>
                            <li>
                                <label for="birthdate">Birthdate</label>
                                <?php echo JHTML::calendar($this->data->birthday,'birthday','birthday','%Y-%m-%d');?>
                            </li>
                            <li>
                                <label for="email">email</label>
                                <input id="email" type="email" name="email" placeholder="myName@myDomain.com" required value="<?php echo $this->mail; ?>">
                            </li>
                            <li>
                                <label for="text">Address</label>
                                <textarea id="address" name="address" rows="3" required><?php echo $this->data->address; ?></textarea>
                            </li>
                        </ol>
                        <button type="submit">UpdateData</button>
                    </fieldset>
                    <input type="hidden" name="userId" value="<?php echo $this->userId; ?>" />
                    <input type="hidden" name="id" value="<?php echo $this->data->id; ?>" />
                </form>
                
            </section>

               <!-- Footer. Display syndication, and some copyright information -->
            <footer id="footer" class="body">
                <div class="footer-data">
                    <h2>The Musashi Project</h2>
                    <h3>A Framework for Managing Your Group</h3>
                    <p>(c)2010 - The Musashi Project</p>                    
                </div>
            </footer>
         
        </musashiContent>
    
    
                    
